package com.ytjj.qmyx.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.kuaidi100.sdk.response.SubscribeResp;
import com.ytjj.common.api.CommonResult;
import com.ytjj.common.api.ResultCode;
import com.ytjj.common.exception.GlobalExceptionHandler;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.model.request.ExpressOrderRequest;
import com.ytjj.qmyx.admin.service.ExpressService;
import com.ytjj.qmyx.admin.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 快递控制器
 * @version 1.0
 *
 */
@RestController
@RequestMapping("express")
@Slf4j
public class ExpressController extends GlobalExceptionHandler {

    private final ExpressService expressService;

    private final OrdersService ordersService;

    public ExpressController(ExpressService expressService, OrdersService ordersService) {
        this.expressService = expressService;
        this.ordersService = ordersService;
    }



    /**
     * 获取快递订单列表
     *
     * @param request
     * @return
     */
    @PostMapping("/getExpressOrdersList")
    public CommonResult getExpressOrdersList(@RequestBody ExpressOrderRequest request){
        return expressService.getExpressOrdersList(request);
    }

    /**
     * 主动更新快递信息接口
     * @param expressId
     * @return
     */
    @GetMapping("/updateExpressInfo")
    @OperLog(operModule = "快递模块", operDesc = "主动更新快递信息接口", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updateExpressInfo(@RequestParam("expressId") Integer expressId){
        expressService.updateExpressInfo(expressId);
        return CommonResult.success(ResultCode.SUCCESS);
    }


    /**
     * 快递100回调
     * @param request
     * @return
     */
//    @RequestMapping("/callBackUrl")
//    public SubscribeResp callBackUrl(HttpServletRequest request){
//        String param = request.getParameter("param");
//        log.debug("快递100订阅推送回调结果|{}",param);
//        SubscribeResp subscribeResp = new SubscribeResp();
//        subscribeResp.setResult(Boolean.TRUE);
//        subscribeResp.setReturnCode("200");
//        subscribeResp.setMessage("成功");
//        JSONObject jsonObject = JSONObject.parseObject(param);
//        ordersService.handleExpressInfo(jsonObject);
//        return subscribeResp;
//    }


}
